package com.jingdianjichi.tool;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class Base64Utils {

   final static Base64.Encoder encoder = Base64.getEncoder();
   final static Base64.Decoder decoder = Base64.getDecoder();

   public static String encode(String text) {
      byte[] textByte = new byte[0];
      try {
         textByte = text.getBytes("UTF-8");
      } catch (UnsupportedEncodingException e) {
         e.printStackTrace();
      }
      String encodedText = encoder.encodeToString(textByte);
      return encodedText;
   }

  
   public static String decode(String encodedText) {
      String text = null;
      try {
         text = new String(decoder.decode(encodedText), "UTF-8");
      } catch (UnsupportedEncodingException e) {
         e.printStackTrace();
      }
      return text;
   }

}